{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing_extensions import TypedDict\n",
    "from langgraph.graph import StateGraph,START,END\n",
    "\n",
    "# {\"foo\":1}\n",
    "\n",
    "\n",
    "class State(TypedDict):\n",
    "    foo: int\n",
    "\n",
    "# def agent_01(state,config) ->State\n",
    "\n",
    "def agent_01(state):\n",
    "    new_state = {\"foo\":state[\"foo\"]+1}\n",
    "    return new_state\n",
    "\n",
    "def cond_edge(state):\n",
    "    if state[\"foo\"]<3:\n",
    "        return \"node_01\"\n",
    "    else:\n",
    "        return END\n",
    "\n",
    "\n",
    "_buider = StateGraph(State)\n",
    "\n",
    "_buider.add_node(\"node_01\", agent_01)\n",
    "\n",
    "_buider.add_edge(START,\"node_01\")\n",
    "_buider.add_conditional_edges(\"node_01\",cond_edge,[\"node_01\",END])\n",
    "\n",
    "\n",
    "_graph = _buider.compile()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import display,Image\n",
    "\n",
    "display(Image(_graph.get_graph().draw_mermaid_png()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "_graph.invoke({\"foo\":0})"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py310",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
